#pragma once

#include <string>
#include "error.h"

namespace anb { namespace net {

class cmd_handler;

class packet {
public:
	packet();
	~packet();

    static const size_t SIZE = 6;

	enum body_type {
		none = 0,
		binary,
		boolean,
		integer,
		uinteger,
		string,
		protobuf,
	};

	unsigned short id;
	unsigned short cmd;

	body_type type;
	bool response;
	bool need_response;
	bool compress;

	error::code err;

	void deserialize_head(char* segment, int len);
	void deserialize_body(char* segment, int len);

protected:

private:

	std::string m_data;

	enum flags {
		flag_body_type_bits = 0x0f,
		flag_response       = 0x10,
		flag_need_response  = 0x20,
		flag_compress       = 0x40,
	};

};

} }
